// pages/u_fpj/u_fpj.js
const app = getApp()
var save_order_comm;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    head:['好评','中评','差评'],
    head_index:-1,
    content:'',
    id:'',
  },
  headtap:function(e){
    var that = this;
    var index = e.currentTarget.dataset.index;
    that.setData({
      head_index:index
    })
  },
  contenttap:function(e){
    this.setData({
      content:e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var id = options.id;
    save_order_comm = app.data.ucenter_url + 'save_order_comm';
    that.setData({
      id:id
    })
  },
  submit:function(e){
    var that = this;
    var id = that.data.id;
    var head = that.data.head;
    var head_index = that.data.head_index;
    var content = that.data.content;
    if(head_index == -1){
      wx.showModal({
        title: '提示',
        content: '请选择好中差评',
        showCancel: false
      })
    }else if(content == ''){
      wx.showModal({
        title: '提示',
        content: '请输入评价内容',
        showCancel: false
      })
    }else{
      var lv = head[head_index];
      wx.showLoading();
      var aid = wx.getStorageSync('uid');
      wx.request({
        url: save_order_comm,
        data: {
          id:id,
          uid:aid,
          lv:lv,
          content:content
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (res) {
          console.log(res.data);
          wx.hideLoading();
          if(res.data.state == 1){
            wx.showModal({
              title: '提示',
              content: '评价提交成功！',
              showCancel: false,
              success:function(e){
                wx.switchTab({
                  url: '/pages/ucenter/ucenter',
                })
              }
            })
          }
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})